
import random
import pygame
from pygame.locals import *

class Jogo:
	#def __init__(self
	pass
	
class Cobra:
	def __init__(self, x=0, y=0):
		self.hdir = 0
		self.vdir = -1
		self.imagem = pygame.image.load("cobra.png").convert_alpha()
		self.cabeca = Cabeca()#(self.x, self.y)
		self.corpo = []
	
	#MOVIMENTOS SNAKE		
	def eventos(self, evento):
		if evento.key == pygame.K_UP and cobra.vdir != 1:
			self.hdir = 0
			self.vdir = -1
		elif evento.key == pygame.K_DOWN and cobra.vdir != -1:
			self.hdir = 0
			self.vdir = 1
		elif evento.key == pygame.K_LEFT and cobra.hdir != 1:
			self.hdir = -1
			self.vdir = 0
		elif evento.key == pygame.K_RIGHT and cobra.hdir != -1:
			self.hdir = 1
			self.vdir = 0
	
	#FAZ O CORPO SEGUIR A CABECA
	def mover(self):
		for i in range (len(self.corpo)-1, 0 ,-1):
			self.corpo[i].x = self.corpo[i-1].x
			self.corpo[i].y = self.corpo[i-1].y
		if len(self.corpo) > 0:
			self.corpo[0].x = self.cabeca.x
			self.corpo[0].y = self.cabeca.y
		self.cabeca.mover()
	
	#DESENHA A SNAKE		
	def draw(self, screen):
		self.cabeca.draw(screen)
		for pedaco in self.corpo:
			pedaco.draw(screen)
			
class Drink(Rect):
	def __init__(self):
		self.x = random.randint(20, 500 - 20)
		self.y = random.randint(20, 500 - 20)
		self.image = pygame.image.load("bebida.png").convert_alpha()
		
	#def verifica_hit(self, cobraPixels):
#		for x, y in cobraPixels:
			#if x >= self.x and y >= self.y and y <= self.y+5 and self.x+5:
		#		return True
				
	def recolocar(self):
		self.x = random.randint(20, largura - 20)
		self.y = random.randint(20, altura - 20)
		
	def draw(self, screen):
		#pygame.draw.rect(screen, (0,255,0), (self.x, self.y, 5,5), 0)
		screen.blit(self.image, (self.x, self.y))
		
		
class Corpo(Rect):
	def __init__(self):
		self.x = 0
		self.y = 0
		self.image = pygame.image.load("cobra.png").convert_alpha()
		self.largura = self.image.get_rect()[2]
		self.altura = self.image.get_rect()[3]	
	def draw(self):
		screen.blit(self.image, (self.x, self.y))	
		
class Cabeca(Rect):
	def __init__(self):
		self.orientacao = (1,0)
		self.x = 0
		self.y = 0
		self.image = pygame.image.load("cobra.png").convert_alpha()
		self.largura = self.image.get_rect()[2]
		self.altura = self.image.get_rect()[3]
		
	def draw(self, screen):
		screen.blit(self.image, (self.x, self.y))	
		
	def mover(self):
		if self.orientacao[1] == 0:
			self.x += self.orientacao[0]*self.largura
		else:
			self.y += self.orientacao[1]*self.altura
			
	def muda_orientacao(self, nova_orientacao):
		self.orientacao = nova_orientacao				
				
		
